layui.define(['table', 'form'], function(exports){
    var table = layui.table;
    var form = layui.form;
    
    var tableComponent = {
        // 渲染表格
        render: function(options) {
            var defaultOptions = {
                page: true,
                limit: 10,
                limits: [10, 20, 30, 50],
                text: {
                    none: '暂无数据'
                },
                parseData: function(res) {
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.data.total,
                        "data": res.data.list
                    };
                }
            };
            
            return table.render($.extend(defaultOptions, options));
        },
        
        // 监听工具条
        tool: function(options) {
            table.on('tool(' + options.filter + ')', function(obj){
                var event = obj.event;
                if(options[event]) {
                    options[event](obj.data, obj);
                }
            });
        },
        
        // 重载表格
        reload: function(id, options) {
            table.reload(id, options);
        }
    };
    
    exports('tableComponent', tableComponent);
}); 